import 'package:flutter/material.dart';
import '../../tokens/colors.dart';
import '../../tokens/spacing.dart';
import '../../tokens/typography.dart';
import '../../tokens/borders.dart';
import '../../tokens/shadows.dart';

/// UI组件库对话框样式
/// 提供统一的对话框样式配置
class UIDialogStyles {
  // 基础对话框装饰
  static BoxDecoration basicDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.dialog,
      boxShadow: UIShadows.dialogShadow,
    );
  }

  // 标准对话框主题
  static DialogTheme standardDialog(ColorScheme colorScheme) {
    return DialogTheme(
      backgroundColor: colorScheme.surface,
      surfaceTintColor: colorScheme.surfaceTint,
      elevation: 3,
      shadowColor: colorScheme.shadow,
      shape: RoundedRectangleBorder(
        borderRadius: UIBorders.dialog,
      ),
      titleTextStyle: UITextStyles.dialogTitle.copyWith(
        color: colorScheme.onSurface,
      ),
      contentTextStyle: UITextStyles.dialogContent.copyWith(
        color: colorScheme.onSurfaceVariant,
      ),
      actionsPadding: const EdgeInsets.fromLTRB(
        UISpacing.lg, 
        UISpacing.sm, 
        UISpacing.lg, 
        UISpacing.lg,
      ),
    );
  }

  // 警告对话框装饰
  static BoxDecoration warningDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.dialog,
      boxShadow: UIShadows.dialogShadow,
      border: Border.all(
        color: UIColors.warning.withOpacity(0.3),
        width: UIBorders.widthMedium,
      ),
    );
  }

  // 错误对话框装饰
  static BoxDecoration errorDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.dialog,
      boxShadow: UIShadows.dialogShadow,
      border: Border.all(
        color: colorScheme.error.withOpacity(0.3),
        width: UIBorders.widthMedium,
      ),
    );
  }

  // 成功对话框装饰
  static BoxDecoration successDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.dialog,
      boxShadow: UIShadows.dialogShadow,
      border: Border.all(
        color: UIColors.success.withOpacity(0.3),
        width: UIBorders.widthMedium,
      ),
    );
  }

  // 信息对话框装饰
  static BoxDecoration infoDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.dialog,
      boxShadow: UIShadows.dialogShadow,
      border: Border.all(
        color: UIColors.info.withOpacity(0.3),
        width: UIBorders.widthMedium,
      ),
    );
  }

  // 全屏对话框装饰
  static BoxDecoration fullScreenDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: BorderRadius.zero,
    );
  }

  // 小尺寸对话框装饰
  static BoxDecoration smallDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.lg,
      boxShadow: UIShadows.elevation2,
    );
  }

  // 大尺寸对话框装饰
  static BoxDecoration largeDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.xl,
      boxShadow: UIShadows.elevation4,
    );
  }

  // 底部工作表样式
  static BoxDecoration bottomSheetDialog(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
      borderRadius: UIBorders.bottomSheet,
      boxShadow: UIShadows.bottomSheetShadow,
    );
  }

  // 对话框头部样式
  static BoxDecoration dialogHeader(ColorScheme colorScheme, {Color? backgroundColor}) {
    return BoxDecoration(
      color: backgroundColor ?? colorScheme.surfaceVariant.withOpacity(0.1),
      borderRadius: const BorderRadius.vertical(
        top: Radius.circular(UIBorders.radiusXL),
      ),
      border: Border(
        bottom: BorderSide(
          color: colorScheme.outline.withOpacity(0.2),
          width: UIBorders.widthThin,
        ),
      ),
    );
  }

  // 对话框底部样式
  static BoxDecoration dialogFooter(ColorScheme colorScheme, {Color? backgroundColor}) {
    return BoxDecoration(
      color: backgroundColor ?? colorScheme.surfaceVariant.withOpacity(0.1),
      borderRadius: const BorderRadius.vertical(
        bottom: Radius.circular(UIBorders.radiusXL),
      ),
      border: Border(
        top: BorderSide(
          color: colorScheme.outline.withOpacity(0.2),
          width: UIBorders.widthThin,
        ),
      ),
    );
  }

  // 对话框内容区域样式
  static BoxDecoration dialogContent(ColorScheme colorScheme) {
    return BoxDecoration(
      color: colorScheme.surface,
    );
  }

  // 模态遮罩样式
  static BoxDecoration modalBarrier(ColorScheme colorScheme, {double opacity = 0.5}) {
    return BoxDecoration(
      color: colorScheme.scrim.withOpacity(opacity),
    );
  }

  // 对话框标题文本样式
  static TextStyle dialogTitleStyle(ColorScheme colorScheme) {
    return UITextStyles.dialogTitle.copyWith(
      color: colorScheme.onSurface,
      fontWeight: FontWeight.w600,
    );
  }

  // 对话框内容文本样式
  static TextStyle dialogContentStyle(ColorScheme colorScheme) {
    return UITextStyles.dialogContent.copyWith(
      color: colorScheme.onSurfaceVariant,
      height: 1.5,
    );
  }

  // 对话框警告标题样式
  static TextStyle warningTitleStyle(ColorScheme colorScheme) {
    return dialogTitleStyle(colorScheme).copyWith(
      color: UIColors.warning,
    );
  }

  // 对话框错误标题样式
  static TextStyle errorTitleStyle(ColorScheme colorScheme) {
    return dialogTitleStyle(colorScheme).copyWith(
      color: colorScheme.error,
    );
  }

  // 对话框成功标题样式
  static TextStyle successTitleStyle(ColorScheme colorScheme) {
    return dialogTitleStyle(colorScheme).copyWith(
      color: UIColors.success,
    );
  }

  // 对话框信息标题样式
  static TextStyle infoTitleStyle(ColorScheme colorScheme) {
    return dialogTitleStyle(colorScheme).copyWith(
      color: UIColors.info,
    );
  }

  // 对话框尺寸配置
  static const double smallDialogWidth = 280.0;
  static const double standardDialogWidth = 400.0;
  static const double largeDialogWidth = 560.0;

  static const double smallDialogMaxHeight = 300.0;
  static const double standardDialogMaxHeight = 400.0;
  static const double largeDialogMaxHeight = 600.0;

  // 对话框内边距配置
  static EdgeInsets get titlePadding => const EdgeInsets.fromLTRB(
    UISpacing.lg, 
    UISpacing.lg, 
    UISpacing.lg, 
    UISpacing.sm,
  );

  static EdgeInsets get contentPadding => const EdgeInsets.fromLTRB(
    UISpacing.lg,
    UISpacing.sm,
    UISpacing.lg,
    UISpacing.lg,
  );

  static EdgeInsets get actionsPadding => const EdgeInsets.fromLTRB(
    UISpacing.lg,
    UISpacing.sm,
    UISpacing.lg,
    UISpacing.lg,
  );

  static EdgeInsets get headerPadding => const EdgeInsets.symmetric(
    horizontal: UISpacing.lg,
    vertical: UISpacing.md,
  );

  static EdgeInsets get footerPadding => const EdgeInsets.symmetric(
    horizontal: UISpacing.lg,
    vertical: UISpacing.md,
  );

  // 获取对话框样式工厂方法
  static BoxDecoration getDialogStyle({
    required String type,
    required ColorScheme colorScheme,
    String size = 'standard',
    Color? backgroundColor,
  }) {
    switch (type.toLowerCase()) {
      case 'warning':
        return warningDialog(colorScheme);
      case 'error':
        return errorDialog(colorScheme);
      case 'success':
        return successDialog(colorScheme);
      case 'info':
        return infoDialog(colorScheme);
      case 'fullscreen':
        return fullScreenDialog(colorScheme);
      case 'bottomsheet':
        return bottomSheetDialog(colorScheme);
      case 'small':
        return smallDialog(colorScheme);
      case 'large':
        return largeDialog(colorScheme);
      default:
        return basicDialog(colorScheme);
    }
  }

  // 获取对话框标题样式
  static TextStyle getTitleStyle({
    required String type,
    required ColorScheme colorScheme,
  }) {
    switch (type.toLowerCase()) {
      case 'warning':
        return warningTitleStyle(colorScheme);
      case 'error':
        return errorTitleStyle(colorScheme);
      case 'success':
        return successTitleStyle(colorScheme);
      case 'info':
        return infoTitleStyle(colorScheme);
      default:
        return dialogTitleStyle(colorScheme);
    }
  }

  // 获取对话框宽度
  static double getDialogWidth(String size) {
    switch (size.toLowerCase()) {
      case 'small':
        return smallDialogWidth;
      case 'large':
        return largeDialogWidth;
      default:
        return standardDialogWidth;
    }
  }

  // 获取对话框最大高度
  static double getDialogMaxHeight(String size) {
    switch (size.toLowerCase()) {
      case 'small':
        return smallDialogMaxHeight;
      case 'large':
        return largeDialogMaxHeight;
      default:
        return standardDialogMaxHeight;
    }
  }
}